﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using OpenAPI.Web.Mvc.Helper;
using OpenAPI.Web.Mvc.Filter;

namespace OpenAPI.Web.Mvc.Controllers
{
    [ManagerAuthFilter]
    [ExceptionFilter]
    public class SchemaController : Controller
    {
        //
        // GET: /Schema/

        public ActionResult Index()
        {
            ViewData["Message"] = "";

            return View();
        }

        public ActionResult Create()
        {
            string message = "";

            if (OpenAPI.BLL.SchemaManager.Create())
            {
                message = "Create Schema Success";
            }
            else
            {
                message = "Create Schema Failure";
            }

            ViewData["Message"] = message;

            return View();
        }

        public ActionResult Drop()
        {
            string message = "";

            if (OpenAPI.BLL.SchemaManager.Drop())
            {
                message = "Drop Schema Success";
            }
            else
            {
                message = "Drop Schema Failure";
            }

            ViewData["Message"] = message;

            return View();
        }


        public ActionResult Init()
        {
            string message = "";

            try
            {
                OpenAPI.BLL.SchemaManager.InitDB();
                message = "Init Database Success";
            }
            catch
            {
                throw;
            }

            ViewData["Message"] = message;

            return View();
        }

    }
}
